package database;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import oracle.jdbc.pool.OracleDataSource;

public class CreateTablePegawai {

    public static void main(String[] args) {
        String jdbcUrl = "jdbc:oracle:thin:@localhost:1521:xe";
        String userid = "HR"; // gantikan dengan username anda
        String password = "renia"; // gantikan dengan password anda

        Connection conn;
        try {
            OracleDataSource ds;
            ds = new OracleDataSource();
            ds.setURL(jdbcUrl);
            conn = ds.getConnection(userid, password);
            System.out.println("Koneksi is OK");
            Statement statement = conn.createStatement();
            String sql = "CREATE TABLE pegawai ("
                    + "idPegawai VARCHAR2(10), CONSTRAINT pegawai_pk PRIMARY KEY (idPegawai),"
                    + "namaPegawai VARCHAR2(30) CONSTRAINT namaPegawai_not_null NOT NULL,"
                    + "username VARCHAR2(30) CONSTRAINT username_not_null NOT NULL,"
                    + "password VARCHAR2(30) CONSTRAINT password_not_null NOT NULL,"
                    + "divisi VARCHAR2(10) CONSTRAINT divisi_not_null NOT NULL,"
                    + "CONSTRAINT divisi_fk FOREIGN KEY (divisi) REFERENCES divisi(idDivisi) )";
            System.out.println("Create Table Divisi succeeded");
            statement.executeUpdate(sql);
        } catch (SQLException ex) {
            System.out.println("error :" + ex.getMessage());
        }
    }
}